﻿using System;
using System.Linq;

namespace TheKitchen.Common
{
    public static class TypeExtensions
    {
        public static bool HasAttribute<TAttribute>(this Type type) where TAttribute : Attribute
        {
            return (type.GetCustomAttributes(typeof (TAttribute), true).Length > 0);
        }

        public static TAttribute FindAttribute<TAttribute>(this Type type) where TAttribute : Attribute
        {
            return (TAttribute)type.GetCustomAttributes(typeof (TAttribute), true).SingleOrDefault();
        }
    }
}
